package com.jiemengshi.server.service;

import com.jiemengshi.server.mapper.FeedbackMapper;
import com.jiemengshi.server.model.Feedback;
import com.jiemengshi.server.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminFeedbackService {
    @Autowired
    private FeedbackMapper feedbackMapper;

    public boolean addFeedback(Feedback feedback) {
        feedback.setCreateTime(DateUtil.getCurrentTime());

        if(feedbackMapper.insertSelective(feedback) > 0)
            return true;
        return false;
    }

    public List<Feedback> listFeedback(int start, int limit) {
        List<Feedback> feedbacks = feedbackMapper.listFeedback(start, limit);
        for (Feedback feedback : feedbacks) {
            feedback.setReplies(feedbackMapper.selectByFeedbackId(feedback.getId()));
        }

        return feedbacks;
    }

    public int countFeedback() {
        return feedbackMapper.countFeedback();
    }
}
